import 'package:fate_blind_box/network/http_config.dart';
import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/ui/guide/download_new.dart';
import 'package:fate_blind_box/ui/login/login_by_pwd.dart';
import 'package:fate_blind_box/ui/login/login_wechat.dart';
import 'package:fate_blind_box/ui/main/navigator.dart';
import 'package:fate_blind_box/ui/user/invite3.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:fate_blind_box/utils/web.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:fluwx/fluwx.dart';
import 'main222.dart';


void main() async {

  if (kIsWeb) {

    // usePathUrlStrategy();
    Web.getParams().forEach((key, value) async {
      await Provider.cache(key, value);
    });
  }
  WidgetsFlutterBinding.ensureInitialized();
  if (Provider.memberId.isEmpty) {
    Provider.memberId = await Provider.getCache("memberId");
  }
  if (HttpConfig.token.isEmpty) {
    HttpConfig.token = await Provider.getCache("token");
  }
  if (!kIsWeb) {
    await _initWechat();
  }
  runApp(defaultApp());
}

Future? _initWechat() async {
  return registerWxApi(
      appId: Provider.wechatAppID,
      doOnAndroid: true,
      doOnIOS: true,
      universalLink: "${HttpConfig.baseUrl}ios"
  );
}

Widget defaultApp() {
  return MaterialApp(
    localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
    ],
    supportedLocales: const [
      Locale('zh', 'CH'),
      Locale('en', 'US'),
    ],
    locale: const Locale('zh'),
    debugShowCheckedModeBanner: false,
    navigatorKey: navKey,
    initialRoute: "/",
    routes: {
      "/share": (context) => const Invite3Ui(),
      "/download": (context) => const DownloadAppUiNew(),
      "/login": (context) => kIsWeb ? const  LoginByWechat() :const LoginByPwd(),
      "/invite": (context) => kIsWeb ? const  LoginByWechat() :const LoginByPwd(),
      "/main": (context) =>  AppMain(),
    },
    theme: ThemeData(
      // splashColor: const Color(0xFFFB6D99),
        primaryColor: ThemeColor.mainColor,
        shadowColor: ThemeColor.shadowColor,
        appBarTheme: const AppBarTheme(
            iconTheme: IconThemeData(color: Colors.black),
            actionsIconTheme: IconThemeData(color: Colors.black),
            backgroundColor: Colors.white
        )
    ),
    home: mainPage(),
    builder: EasyLoading.init(),
  );
}

Widget mainPage() {
  // return const InviteUi();
  // return const FansUi();
     return  AppMain();
  // return const LoginUi();
  // return LoginVerifyCode("15201163270", Provider.loginSign);
     return const LoginByPwd();
  // return const LoginByWechat();
  // return const LoginBindWxUi("");
  // return const ProfileCompleteUi();
  // return const MyPointsUsi();
  // return const FateLineUi();
  // return const FateListUi();
  // return const FateSuccessUi();
  // return const MatcherDetailUi("");  // 红娘详情
  // return const MomentPublishUi(); // 发布帖子
  // return const BlindFormUi(); // 发布帖子 - 完善信息
  // return const BlindActiveUi(); // 相亲活动
  // return const BlindTrustUi()xx; // 相亲活动
  // return const BlindDetailUi(); //缘分详情
  // return const CyclePublishUi(); // 发布圈子
  // return const CycleListUi(); //     圈子列表
  // return const CycleDetailUi(data: {},); // 圈子详情
  // return UserProfileUi(memberId: Provider.memberId); // 用户资料页
  // return const ProfileEditUi(); // 编辑资料
  // return const WalletUi();  //我的钱包
  // return const MineCycleUi();
  // return const BlindTrustUi(); // 诚信约会
  // return const InviteUi(); // 邀请码
  // return const Invite2Ui(); // 邀请码
  // return const Invite3Ui(); // 邀请码
  // return const Pay4ChangeUi(); // 增加偶遇
  // return const ProfileCompleteV2Ui();  // 邀请好友 完善信息
}
